<template>
  <el-dialog :title="this.type==='add'?'新增茶桌':'修改茶桌'" :visible.sync="activeTopTemp" :close-on-click-modal="false" @close="dialogFormVisible=false">
    <el-form :model="formObj" ref="formObj" :rules="rules">
      <el-form-item label="茶桌ID">
        <el-input v-model="formObj.id" :disabled="true" placeholder="新增茶桌时系统分配ID,不可指定"></el-input>
      </el-form-item>
      <el-form-item label="茶桌编号" prop="deskNo">
        <el-input v-model="formObj.deskNo" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="onSubmit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {doAddDesk, doUpdateDesk} from "@/api/desk";

export default {
  name: "deskDialog",
  props:{
    type:String,
    dialogFormVisible:Boolean,
    desk:Object
  },
  data() {
    return{
      activeTopTemp:this.dialogFormVisible,
      formObj:this.desk,
      rules: {
        deskNo:[ { required: true, message: '请输入茶桌编号', trigger: 'blur' }]
      },
      allType: []
    }
  },
  methods:{
    onSubmit() {
      //参数校验
      this.$refs.formObj.validate((valid) => {
        if (valid) {
          if (this.type==='add'){
            doAddDesk(this.formObj).then(res=>{
              if (res.code===200){
                this.activeTopTemp=false;
                this.$emit('change',true)
              }
            })
          }else{
            doUpdateDesk(this.formObj).then(res=>{
              if (res.code===200){
                this.activeTopTemp=false;
                this.$emit('change',true)
              }
            })
          }
        } else {
          return false;
        }
      })
    }
  },watch:{
    dialogFormVisible(){
      this.activeTopTemp=this.dialogFormVisible;
    },
    desk(){
      this.formObj = this.desk;
    }
  },
  mounted() {
  }
}
</script>

<style scoped>

</style>